#include<stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <iostream>


/*
I->入栈，O->出栈，判断IIOO这样的序列是否合法
*/

bool Judge(char c[]){
    int i=0,k=0;
    while (c[k]!='\0')
    {
        if (c[k]=='I') i=i+1;
        else i=i-1;
        if (i<0) return false;
        k++;
    }
    if (i==0) return true;
    else return false;
}

int main(){
    char c1[9] = {'I','O','I','I','O','I','O','O','\0'};
    char c2[9] = {'I','O','O','I','O','I','I','O','\0'};
    char c3[9] = {'I','I','I','O','I','O','I','O','\0'};
    char c4[9] = {'I','I','I','O','O','I','O','O','\0'};
    printf("%d", Judge(c4));    
    system("pause");
    return 0;
}